package qingke.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertyManager {

	private static Map<String, PropertyManager> propsMap = new HashMap<>();

	public static synchronized PropertyManager getInstance(String propsFile) {
		if (!propsMap.containsKey(propsFile)) {
			propsMap.put(propsFile, new PropertyManager(propsFile));
		}
		return propsMap.get(propsFile);
	}

	private Properties prop;

	private PropertyManager(String propsFile) {
		try {
			prop = new Properties();
			prop.load(new FileInputStream(propsFile));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getProperty(String key) {
		return prop.getProperty(key);
	}

	public String[] getPropertyList(String key) {
		String propValue = prop.getProperty(key, "");
		return propValue.split(",");
	}
}
